﻿<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style type="text/css">
		#div1{width: 300px;height: 100px;background: #ff0000;}
	</style>
    	<script type="text/javascript">
            function getStyle(str0, str1)
            {
                if(str0.currentStyle)
                {
                    return str0.currentStyle[str1];
                }
                else
                {
                    return getComputedStyle(str0)[str1];
                }
            }

            //function css(obj, attr, value)
            function css(str0,str1,str2)
            {
                if(arguments.length==2)	//获取
                {
                    return getStyle(str0, str1);
                }
                else if(arguments.length==3)	//设置
                {
                    //obj.style[attr]=value;
                    str0.style[str1]=str2;
                }
            }

            window.onload=function ()
            {
                var oBtn=document.getElementById('btn1');
                var oDiv=document.getElementById('div1');

                oBtn.onclick=function ()
                {
                    css(oDiv, 'background', 'green');
                    alert(css(oDiv, 'width'));
                }
        }
	</script>
</head>
<body>
	<input type="button" id="btn1" value="按钮" />
	<div id="div1"></div>
    <div></div>
</body>
</html>